<?php

namespace app\hpt\controller;

use think\Request;

class IndexController extends BaseController
{

    public function index(Request $request)
    {
        $page = $request->get('page');
        $pageSize = $request->get('pgsize');
        $order = $request->get('order');
        $orderType = $request->get('odtype');
        $userInfo = [
            'history_list' => '',
        ];

        if (!empty($this->curUser)) {
			$userInfo = array_merge($userInfo, $this->curUser);
            $userInfo['history_list'] = json_decode($userInfo['history_list'], true);
        }

        $condition = [
            'field' => 'game_name,game_logo,brief,multiple_list,play_url',
            'order' => $order,
            'order_type' => $orderType,
            'cache_key'=>'game_list',
            'page' => $page,
            'page_size' => $pageSize,
        ];
        //游戏列表
        $gameList = model('game')->getList($condition);
        foreach ($gameList as &$v) {
            $v['multiple_list'] = json_decode($v['multiple_list'], true);
        }
        unset($v);
        $this->assign(['userInfo' => $userInfo, 'gameList' => $gameList]);
        return $this->fetch();
    }

    public function play()
    {
        $gameEname = $this->request->param('game');
        echo 'game: ' . $gameEname . '<br>';
        echo '<a href="' . url('/') . '">返回大厅</a>';
    }

    /**
     * 个人信息修改接口
     */
    public function setUserInfo(){
        $userInfo = session('user');
        $uname = $userInfo['user_login'];
        $nickname = $this->request->get('nickname', '', 'string');
        $avatar = $this->request->get('avatar', 0, 'int');
        if ($nickname != '') $data['user_nickname'] = $nickname;
        if ($avatar != '') $data['avatar'] = $avatar;
        if (isset($data)) {
            $re=model('user')->setInfo(['user_login'=>$uname],$data);
            return $re;
        } else {
            return ['code' => 1, 'msg' => '未做任何修改'];
        }
    }
}
